<?php

namespace App\Kuafu\Pay\Model;

use App\Kuafu\Base\Model\BaseModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class MyPayRefundCallback extends BaseModel
{
    use HasFactory;

    protected $connection = 'mysql';
    protected $table      = 'my_pay_refund_callback';
    protected $primaryKey = 'id';
    public    $timestamps = true;

    protected $fillable = [
        'url',
        'param',
        'num',
        'response',
    ];

    public static function addData(string $url, int $num, array $param): int
    {
        return self::query()->insertGetId([
            'url'      => $url,
            'num'      => $num,
            'param'    => json_encode($param),
            'createdAt' => time(),
            'updatedAt' => time(),
        ]);
    }

    /**
     * 更新日志response
     * @param int $id
     * @param string $responseData
     * @return int
     */
    public static function editResponseData(int $id, string $response): int
    {
        return self::query()->where('id', $id)->update(['response' => $response]);
    }
}
